<?php

class SiteController extends Controller {

    /**
     * Declares class-based actions.
     */

    /**
     * @return array action filters
     */
    public function filters()
    {
        return array(
          //  'accessControl', // perform access control for CRUD operations
        );
    }
    
    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules()
    {
       
    }

        
        
        
        
        
        
        
    public function actions() {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }

    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex() {
       //$this->render(array("//site/index"));
        $this->render('index');
    }

    /**
     * This is the action to handle external exceptions.
     */
    public function actionError() {
        if ($error = Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

    
    
    
    






    public function actionLogin() {
        
        
 $this->layout = false;

    
        $model=new LoginForm;

		// if it is ajax validation request
		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}

		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login())
				$this->redirect(Yii::app()->user->returnUrl);
		}
		// display the login form
		$this->render('login',array('model'=>$model));
        
        
    }

    public function actionLogout() {
        unset(Yii::app()->session["username"]);
        unset(Yii::app()->session["emp_name"]);

        $this->redirect(array("site/login"));
    }

    public function actionListSchedules() {

        $data = tbBoatSchedules::model()->findAll('
      DATE_UPSTATUS =:TimeDate
      AND SCHEDULE_STATUS = :TimeStatus
      AND BOATPORT_ID=:parent_id', array(':parent_id' => (int) $_POST['PLACE_CODE'],
            ':TimeDate' => date('Y-m-d'),
            ':TimeStatus' => 'OPEN',
                ));

        $data = CHtml::listData($data, 'ID', 'TICKET_TIME');
        echo "<option value=''>Select </option>";
        foreach ($data as $value => $name) {
            echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
        }
    }

}